﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FirstHomeWork.Observer
{
    public class PeopleObServer : IObject
    {
        public override void Show()
        {
            this.GoFishing();
        }

        /// <summary>
        /// 人钓鱼
        /// </summary>
        public void GoFishing()
        {
            Console.WriteLine("人钓鱼");
        }

        public Action ActionHande;

        public event Action ActionHandeEvent;

        public void PeopleDelegate()
        {
            Console.WriteLine("执行委托:"+this.GetType().Name);
            ActionHande?.Invoke();
        }

        public void PeopleDelegateEvent()
        {
            Console.WriteLine("执行委托事件:" + this.GetType().Name);
            ActionHandeEvent?.Invoke();
        }

        public List<IObject> ObserverList = new List<IObject>();

        public void AddObserver(IObject observer)
        {
            ObserverList.Add(observer);
        }

        public void PeopleObserver()
        {
            Console.WriteLine("面向对象观察者模式："+this.GetType().Name);
            foreach (IObject item in ObserverList)
            {
                item.Show();
            }
        }
    }
}
